package org.lex.ftp.ui;

import java.util.List;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

import org.lex.ftp.FTP;

public class SessionsTableModel extends AbstractTableModel {
	private static final SessionsTableModel instance = new SessionsTableModel();
	private static final String[] COLUMN_NAMES = { "#", "Server" };
	private List<FTP> data = null;

	public static final SessionsTableModel getInstance() {
		return instance;
	}

	public void add(FTP app) {
		this.data.add(app);
		this.fireTableDataChanged();
	}

	public void remove(FTP app) {
		this.data.remove(app);
		this.fireTableDataChanged();
	}

	public String getColumnName(int column) {
		return COLUMN_NAMES[column];
	}

	public int getColumnCount() {
		return COLUMN_NAMES.length;
	}

	public int getRowCount() {
		return data.size();
	}

	public Object getValueAt(int row, int column) {
		if (0 == column)
			return row;
		FTP app = data.get(row);
		if (app.getFTPExplorer().isConnected())
			return app.getFTPExplorer().getFTPModel().getFTPURL().getServer();
		else
			return "Not connected";
	}

	private SessionsTableModel() {
		this.data = new Vector<FTP>(2);
	}
}
